package root.server;

import java.util.ArrayList;
import java.util.Scanner;


public class MenuPrincipal {
	
	protected static Sistema sistema = new Sistema();
	private static ArrayList<MenuLogado> listaLogados = new ArrayList<MenuLogado>();
	
	public static void main(String[] args) {
		boolean sistemaON = true;
		while (sistemaON) {
			String opcao1 = MenuInicial();
			if(opcao1.equals("1")){ //REGISTRAR
				MenuRegister();
			}else if(opcao1.equals("2")){ //FAZER LOGIN
				MenuLogin();
			}else if(opcao1.equals("3")){ //SAIR
				sistema.encerrarSistema();
				break;
			}else{
				System.out.println("Opcão inválida");
			}
		}

	}
	
	private static String MenuInicial() {
		System.out.print(
				"\n    ******** PLUMBUM  *********\n"
				+ " ********** Social Network **********\n"
				+ "  [1] - Register                    *\n" 
				+ "  [2] - Log in                      *\n"
				+ "  [3] - Exit                        *\n"
				+ " ************************************\n"
				+ ">> ");
		return getScanner().next();
	}
	
	private static Scanner getScanner() {
		return new Scanner(System.in);
	}
	
	private static void MenuRegister() {
		System.out.print("Type your name (ex.: Nazareno Andrade):");
		String nome = getScanner().nextLine();
		System.out.print("Type your adress (ex.: City, State):");
		String adress = getScanner().nextLine();
		System.out.print("Type your login (ex.: nazareno): ");
		String login = getScanner().next();
		try {
			sistema.criarUsuario(login, nome, adress);
			System.out.println("User successfully registered");
		} catch (Exception e) {
			System.out.println("**Error: "+e.getMessage());
			System.out.println("Try again.\n");
			MenuRegister();
		}

	}
	private static void MenuLogin(){
		System.out.print("Type your login:");
		String login = getScanner().next();
		try{
			MenuLogado run = new MenuLogado(login);
			listaLogados.add(run);
			run.main();
			
		}catch(Exception e){
			System.out.println("**Error: "+e.getMessage());
			System.out.println("Try again.");

		}
	}
	
}
